<?
$smarty=new Smarty();
if(!ANTIHACK) die("ANTIHACK...");

if($_GET["ajax"]=="showhome")
{
	$id=$_GET["id"];
	$value=$_GET["value"];
	$q=query("select * from post where id=$id");
	$r=fetch($q);
	if(update(array("is_showhome" => $value),"post","id=$id"))
		echo "0";
	else
		echo "1";
	exit;
}
if($_GET["ajax"]=="showtrailer")
{
	$id=$_GET["id"];
	$value=$_GET["value"];
	$parent=$_GET["parent"];
	$q=query("select * from post where id=$id");
	$r=fetch($q);
	if($r["trailer"]==""){
		echo "2";
		exit;
	}
	update(array("is_showtrailer" => "0"),"post","parent=$parent");
	if(update(array("is_showtrailer" => $value),"post","id=$id"))
		echo "0";
	else
		echo "1";
	exit;
}
$smarty->assign("nameact","Quản lý bài viết");
include("../includes/language_vi.php");
include_once("./includes/getlistMenu.php");
include_once("./includes/paging.php");
$per=query("select `group`.`permission` as permission from user,`group` where `user`.`id`=$_SESSION[id] and `user`.`group` = `group`.`id`");
	$fper=fetch($per);
	$Aper=json_decode($fper['permission'],true);
$menu=getlistMenu("menuid",intval($_GET['type']), "box",$Aper,1);
$smarty->assign("listmenu",$menu);
$type="1=1 ";
$link="";
if(isset($_GET['type']) && intval($_GET['type'])>0)
{
	$type .= " and parent=".intval($_GET['type']);
	$link .="type=".intval($_GET['type']);
}
$table="post";
$limit=30;
$numpage=20;
$act="manager-post";
$page=intval($_GET['page']);
$listpage= pagingwhere($table,$type,$act,$link,$page,$total,$start,$limit,$numpage);

$query=query("select * from post where $type order by time desc limit $start,$limit");
$i=$start;
while($r=fetch($query))
{
	$menuid=query("select name from menu where id = ".$r['parent']." limit 1");
	$mn=fetch($menuid);
	if(!$Aper[mn][$r['parent']])
		continue;
	$r['parentid']=$r['parent'];
	$r['parent']=$mn["name"];
	if($r['is_active']==1) $r['is_active']="Hiển thị";
		else $r['is_active']="Ẩn";
	$r['count']=++$i;
	$posts[]=$r;
}
$smarty->assign("cur_page",$page);
$smarty->assign("page",$listpage);
$smarty->assign("total",$total);
$smarty->assign("posts",$posts);

$smarty->display("manager-post.htm");

?>